package com.jiayou.im.filter

import cn.hutool.json.JSONUtil
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
@author 李 双
@data   2020-11-20  16:39
@info
 */
@Component
class LoginFilter : HandlerInterceptor {
    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
        val auth = request.getHeader("auth")
        return if (auth == null || auth != "73913da7-508b-4646-b8ae-ef6458f41153") {
            response.status = 403
            response.characterEncoding = "UTF-8"
            response.contentType = "application/json;charset=utf-8"
            response.writer.write(JSONUtil.parseObj("{code:403,data:'拒绝服务'}").toString())
            response.writer.flush()
            false
        } else
            true
    }
}